package com.leetcode.August;

/**
 * @Description: 169. 多数元素
 * @Author: Mr.Fxy
 * @CreateTime: 2024-08-16 11:00
 */
public class LC169多数元素 {
    public int majorityElement(int[] nums) {
        int constant = 0, number = 0;
        for (int num : nums) {
            if (constant == 0) {
                number = num;
            }
            if (number == num) {
                constant++;
            } else {
                constant--;
            }
        }
        return nums[number];
    }
}
